package sapling.logic.algorithm.pcb.dispatcher;

import sapling.main.OSEnvironment;

public class FCFSDispatcher extends Dispatcher {

	public FCFSDispatcher(OSEnvironment env) {
		super(env);
	}

	@Override
	protected boolean switchOver() {
		this.env.getPcbRunning().setLiveLong(this.env.getPcbRunning().getLiveLong()-1);
		if (this.env.getPcbRunning().getLiveLong() <= 0) {
			this.env.getPcbRunning().release();
			if (this.env.getPcbQueue().isEmpty()) {
				this.env.setPcbRunning(null);
				return true;
			}
			this.env.setPcbRunning(this.env.getPcbQueue().dequeue());
		}
		return false;
	}
}
